<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 随机数 0~1 包含0不包含1;
        // console.log(Math.random());

        //0-5  0-0.9
        // nin + Math.floor(Math.random() + (Max - nin + 1))
        // console.log(Math.floor(Math.random() * (5 + 1)));
        // 2-5
        // console.log(2 + Math.floor(Math.random() * (5 - 2 + 1)));

        const student = ["AA", "BB", "CC", "DD", "EE"];

        // const index = Math.floor(Math.random() * (student.length));

        // console.log(student[index]);

        // 2-5
        // const index = 2 + Math.floor(Math.random() * (student.length - 2));
        // console.log(student[index]);

        // 2-3
        // const index = 2 + Math.floor(Math.random() * (4 - 2));
        // console.log(student[index]);

        function arrayRandomValue(array, start = 1, end) {
            end = end || array.length;
            //console.log(end);
            start--;
            const index = start + Math.floor(Math.random() * + (end - start));
            console.log(index);
            return array[index];
        }
        console.log(arrayRandomValue(student));
    </script>
</body>

</html>